import Router from 'vue-router'
import Layout from '@/layout'
// 引入路由表
import asyncRouterMap from './constantRouterMap'


const originalPush = Router.prototype.push;
Router.prototype.push = function push(location, onResolve, onReject) {
    if (onResolve || onReject)
        return originalPush.call(this, location, onResolve, onReject);
    return originalPush.call(this, location).catch((err) => err);
}

export const constantRouterMap = [{
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    name: '主页',
    hidden: true,
    children: [{
        path: 'dashboard',
        name: '总览',
        component: () => import('../components/LandingPage/SystemInformation.vue')
    }]
}, {
    path: '/login',
    component: () => import('@/views/login'),
    hidden: true
}, {
    path: '*',
    component: () => import('@/views/404'),
    hidden: true
}]
export const asyncRoutes = asyncRouterMap

const createRouter = () => new Router({
    scrollBehavior: () => ({y: 0}),
    routes: constantRouterMap
})

export function resetRouter() {
    const newRouter = createRouter()
    router.matcher = newRouter.matcher
}

const router = createRouter()

export default router
